ig.module('game.entities.button').requires('impact.entity').defines(function(){
    Button = ig.Entity.extend({
        size: {
            x: 210,
            y: 60
        },
        isMouseEnter: false,
        enabled: true,
		visible:true,
        click: undefined,
        text: undefined,
        animSheet: new ig.AnimationSheet('media/button.png', 210, 60),
        init: function(x, y, settings){
            this.parent(x, y, settings);
            this.addAnim('idle', 0.1, [0]);
            this.addAnim('hover', 0.1, [1]);
            this.click = settings.click;
            this.text = new ig.Text(settings.text,"#ffffff","bold 1em Verdana");
            this.text.baseLine = "middle";
            this.text.align = "center";
        },
        update: function(){
            if (this.enabled && this.visible) {
                if ((ig.input.mouse.x > this.pos.x && ig.input.mouse.x < this.pos.x + this.size.x) &&
                (ig.input.mouse.y > this.pos.y && ig.input.mouse.y < this.pos.y + this.size.y)) {
                    if (!this.isMouseEnter) {
                        this.isMouseEnter = true;
						this.mouseenter();
                    }
                }
                else {
                    if (this.isMouseEnter) {
                        this.isMouseEnter = false;
						this.mouseout();
                    }
                }
                
                if (ig.input.released('click') && this.isMouseEnter) {
                    this.mouseclick();
                }
            }
            else {
                if (this.isMouseEnter) {
                    this.isMouseEnter = false;
					this.mouseout();
                }
            }
        },
        draw: function(){
			if(!this.visible){
				return;
			}
            this.parent();
            this.text.draw(this.pos.x + this.size.x / 2, this.pos.y + this.size.y / 2, 200);
        },
        mouseenter: function(){
            this.currentAnim = this.anims.hover.rewind();
        },
        mouseout: function(){
            this.currentAnim = this.anims.idle.rewind();
        },
        mouseclick: function(){
            this.click();
        }
    });
});
